<template>
	<div class="my-service bg-white mx-[20rpx] mt-[20rpx] rounded-lg p-[30rpx]">
		<div v-if="content.title" class="title font-medium text-lg">
			<div>{{ content.title }}</div>
		</div>
		<div v-if="content.style == 1" class="grid grid-cols-4 gap-x-9 gap-y-7">
			<div v-for="(item, index) in showList" :key="index" class="flex flex-col items-center pt-[40rpx]" @click="handleClick(item.link)">
				<u-image width="52" height="52" :src="getImageUrl(item.image)" alt="" />
				<div class="mt-[22rpx] text-sm" style="white-space: nowrap;">{{ item.name }}</div>
			</div>
		</div>
		<div v-if="content.style == 2">
			<div
				v-for="(item, index) in showList"
				:key="index"
				class="flex items-center border-light border-solid border-0 border-b h-[100rpx] px-[24rpx]"
				@click="handleClick(item.link)"
			>
				<u-image width="48" height="48" :src="getImageUrl(item.image)" alt="" />
				<div class="ml-[20rpx] flex-1 text-sm" style="white-space: nowrap;">{{ item.name }}</div>
				<div class="text-muted">
					<u-icon name="arrow-right" />
				</div>
			</div>
		</div>
	</div>
</template>
<script lang="ts" setup>
import { useAppStore } from '@/stores/app';
import { navigateTo } from '@/utils/util';
import { computed } from 'vue';
import { useUserStore } from '@/stores/user';
import wx from 'weixin-js-sdk'	
const props = defineProps({
	content: {
		type: Object,
		default: () => ({})
	},
	styles: {
		type: Object,
		default: () => ({})
	}
});
const { getImageUrl } = useAppStore();
const { userInfo } = useUserStore();
const handleClick = (link: any) => {
	if (link.path == '/pages/hexiao/hexiao') {
		// #ifdef H5
		wx.scanQRCode({
			needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
			scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
			success: function (res) {
				const result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
				// 扫码之后的逻辑处理
				// console.log(result);
				// 在这里处理扫描结果
				uni.navigateTo({
					url:'/pages/hexiao/hexiao?uid='+result+'&sid='+userInfo.id
				})
			}
		});
		// #endif
		// #ifdef MP-WEIXIN
		uni.scanCode({
			success: (res) => {
				// 在这里处理扫描结果
				uni.navigateTo({
					url:'/pages/hexiao/hexiao?uid='+res.result+'&sid='+userInfo.id
				})
			},
			fail: (err) => {
				console.log(err);
				// 在这里处理扫描失败的情况
			}
		});
		// #endif
	}else if(link.path == '/pages/share/share'){
		uni.navigateTo({
			url:'/pages/share/share?id='+userInfo.sn+'&nickname='+userInfo.nickname
		})
	} else {
		navigateTo(link);
	}
};

const showList = computed(() => {
	return props.content.data?.filter((item: any) => item.is_show == '1') || [];
});
</script>

<style lang="scss"></style>
